package com.chyb.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.chyb.cloud.apis.openFeignApi;
import com.chyb.cloud.entities.PayDTO;
import com.chyb.cloud.resp.ResultData;
import com.chyb.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/consumer")
public class OrderController {
    @Resource
    private openFeignApi openFeignApi;

    @PostMapping("/add")
    public ResultData add(@RequestBody PayDTO payDTO) {
        return openFeignApi.add(payDTO);
    }

    @GetMapping("/getAll")
    public ResultData getAll() {
        System.out.println("-------支付微服务远程调用，按照id查询订单支付流水信息");
        ResultData resultData = null;
        try {
            System.out.println("调用开始-----:" + DateUtil.now());
            resultData = openFeignApi.getAll();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("调用结束-----:" + DateUtil.now());
            ResultData.fail(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }
        return resultData;
    }

    @GetMapping("/getInfo")
    public ResultData getInfo() {
        String info = openFeignApi.getInfo();
        return ResultData.success(info);
    }
}
